package com.app.freshmenapp.service.impl;

import com.app.freshmenapp.dao.MessageDao;
import com.app.freshmenapp.entity.Messages;
import com.app.freshmenapp.service.MessagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * @Auther: Administrator
 * @Date: 2019.07.20 17:06
 * @Description: 留言信息服务层
 */

@Service
@SuppressWarnings("all")
public class MessagesServiceImpl implements MessagesService {

    @Autowired
    private MessageDao messageDao;

    @Override
    public boolean addMessages(Messages messages) {
        Messages messages1 = messageDao.saveAndFlush(messages);
        if(messages1!=null){
            return true;
        }
        return false;
    }

    @Override
    public boolean deleteInforms(Integer id) {
        if(messageDao.existsById(id)){
            messageDao.deleteById(id);
            return true;
        }
        return false;
    }

    @Override
    public boolean updateMessages(Messages messages) {
        Messages messages1 = messageDao.saveAndFlush(messages);
        if(messages1!=null){
            return true;
        }
        return false;
    }

    @Override
    public Messages findById(Integer id) {
        if (messageDao.existsById(id)){
        Optional<Messages> optionalMessages=messageDao.findById(id);
        return optionalMessages.get();
        }
        return null;
    }

    @Override
    public List<Messages> findAllMessages() {
       return messageDao.findAll();
    }
}
